package 泛型;

class Stack<T> {
    public T[] objects;
    public int top;

    public Stack() {
        this.objects = (T[]) new Object[10];//注意 需要强转为T[]!!!
    }

    public void push(T obj) {
        this.objects[this.top++]=obj;
    }

    public T get() {
        return objects[this.top--];
    }
}

public class TestDemo {
    public static void main(String[] args) {
        Stack<Integer> stack=new Stack<>();
        stack.push(1);
        //stack.push("sjjjj");


//        泛型.Stack stack=new 泛型.Stack();
//        stack.push(1);
//        stack.push("sjjjj");

    }
}
